<template>
  <div>
    <Invites ref="invites" />
    <JoinedCommunities ref="joinedCommunities" />
  </div>
</template>

<script>
import Invites from './invites';
import JoinedCommunities from './joined-communities';

export default {
  name: 'SpaceSettingsCommunities', // 空间关联的社区管理
  components: { Invites, JoinedCommunities },
  props: {
    active: { // 本组件是否激活
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      mounted: false,
    };
  },
  created() {
    this.$root.$on('refreshSpacesCommunities', () => {
      this.$refs.invites.loadInvites();
      this.$refs.joinedCommunities.loadJoinedCommunities();
    });
  },
  mounted() {
    if (this.active) {
      this.mounted = true;
      this.$refs.invites.loadInvites();
      this.$refs.joinedCommunities.loadJoinedCommunities();
    }
  },
  watch: {
    active() {
      if (!this.mounted) {
        this.mounted = true;
        this.$refs.invites.loadInvites();
        this.$refs.joinedCommunities.loadJoinedCommunities();
      }
    },
  },
};
</script>

<style></style>
